<template>
  <el-select
    v-model="innerValue"
    :multiple="props.multiple"
    :filterable="props.filterable"
    :allow-create="props.allowCreate"
    :default-first-option="props.defaultFirstOption"
    :placeholder="props.placeholder"
    @change="handleChange"
    style="width: 100%"
  >
    <el-option
      v-for="item in props.options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
</template>

<script>
export default {
  name: 'JTagsSelect',
  props: {
    value: {
      type: [String, Array],
      default: ''
    },
    multiple: {
      type: Boolean,
      default: false
    },
    filterable: {
      type: Boolean,
      default: false
    },
    allowCreate: {
      type: Boolean,
      default: false
    },
    defaultFirstOption: {
      type: Boolean,
      default: false
    },
    placeholder: {
      type: String,
      default: '请选择'
    },
    options: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      innerValue: this.value
    }
  },
  watch: {
    value: {
      handler(newVal) {
        this.innerValue = newVal
      },
      immediate: true
    }
  },
  methods: {
    handleChange(value) {
      this.$emit('input', value)
    }
  }
}
</script>

<style scoped>
.el-select {
  width: 100%;
}
</style>
